﻿
Ext.define('SHApp.ClientInfo.ProductGroup.PanelGrid', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.panelgrid',
    requires: ['SHApp.ClientInfo.BagManage.Grid', 'SHApp.ClientInfo.ProductGroup.InfoGrid', 'SHApp.ClientInfo.ProductGroup.AgentGrid'],
    layout: { type: "border" },
    basicGrid: null,
    productGroup: null,
    agentGrid: null,
    pvalue: 0,
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        this.createItem(); //初始化分页条
        this.callParent(arguments);
    },
    createItem: function () {
        var me = this;

        var basicGrid = Ext.create("SHApp.ClientInfo.BagManage.Grid", {
            title: "合同基本信息",
            flex: 0.6,
            pvalue: me.pvalue,
            split: true,
            region: "west",
            creatColumns: function () {
                var me = this;
                me.columns = [{
                    text: "Id",
                    flex: 1,
                    dataIndex: 'Id',
                    sortable: false,
                    hidden: true
                }, {
                    text: "合体编号",
                    width: 100,
                    dataIndex: 'Code',
                    sortable: true
                }, {
                    text: "合体名称",
                    width: 120,
                    dataIndex: 'Name',
                    sortable: true
                }, {
                    text: "甲方名称",
                    width: 120,
                    dataIndex: 'CompanyName',
                    sortable: true
                }, {
                    text: "甲方ID",
                    width: 100,
                    dataIndex: 'CompanyID',
                    sortable: true,
                    hidden: true
                }, {
                    text: "合同起始日期",
                    width: 120,
                    dataIndex: 'StartDateTime',
                    sortable: true,
                    renderer: formatDate,
                    hidden: true
                }, {
                    text: "合同截止日期",
                    width: 120,
                    dataIndex: 'EndDateTime',
                    sortable: true,
                    renderer: formatDate,
                    hidden: true
                }];
            },
            creatTbar: function () {
                var me = this;
                me.tbar = [
		    {
		        xtype: 'textfield',
		        disabled: false,
		        fieldLabel: '甲方名称:',
		        labelWidth: 60,
		        name: 'CompanyName',
		        id: me.txtCompanyNameID,
		        width: 150
		    }, {
		        xtype: 'button',
		        text: '查询',
		        iconCls: 'icon-btn-search',
		        handler: function () {
		            me.clearFilters();
		            var vCompanyName = me.down("#" + me.txtCompanyNameID).getValue();
		            if (vCompanyName && vCompanyName.length > 0) {
		                me.addFilter("CompanyName", vCompanyName);
		            }
		            me.loadByFilter();
		        }
		    }];
            }
        });

        basicGrid.on("selectionchange", function (model, records) {
            var Code = "";
            var CompanyID = "";
            if (records.length > 0) {
                Code = records[0].data.Code;
                CompanyID = records[0].data.CompanyID;
            }
            me.productGroup.loadByUserID(Code, CompanyID);

        });

        this.basicGrid = basicGrid;

        var productGroup = Ext.create("SHApp.ClientInfo.ProductGroup.InfoGrid", {
            title: "产品组合信息",
            // width: 400,
            flex: 1,
            region: "center",
            pvalue: me.pvalue
        });

        me.productGroup = productGroup;

        var agentGrid = Ext.create("SHApp.ClientInfo.ProductGroup.AgentGrid", {
            title: "委托设置",
            // width: 400,
            flex: 0.4,
            split: true,
            region: "east",
            pvalue: me.pvalue
        });

        me.agentGrid = agentGrid;

        me.items = [me.basicGrid, me.productGroup, me.agentGrid];
    }
})

